#define _DEFAULT_SOURCE

#include <check.h>
#include <stdio.h>
#include <stdlib.h>

#include "s21_matrix.h"

#define M4X4                                                        \
  {                                                                 \
    {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, { 13, 14, 15, 16 } \
  }
#define M4X4t                                                       \
  {                                                                 \
    {1, 5, 9, 13}, {2, 6, 10, 14}, {3, 7, 11, 15}, { 4, 8, 12, 16 } \
  }
#define M4X4n                                                  \
  {                                                            \
    {-1, -2, -3, -4}, {-5, -6, -7, -8}, {-9, -10, -11, -12}, { \
      -13, -14, -15, -16                                       \
    }                                                          \
  }
#define M4X4m2                                                           \
  {                                                                      \
    {2, 4, 6, 8}, {10, 12, 14, 16}, {18, 20, 22, 24}, { 26, 28, 30, 32 } \
  }
#define M4X4z                                                \
  {                                                          \
    {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, { 0, 0, 0, 0 } \
  }
#define M4X4mult                                                       \
  {                                                                    \
    {90, 100, 110, 120}, {202, 228, 254, 280}, {314, 356, 398, 440}, { \
      426, 484, 542, 600                                               \
    }                                                                  \
  }
#define E4X4                                                 \
  {                                                          \
    {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, { 0, 0, 0, 1 } \
  }
#define E3X3                          \
  {                                   \
    {1, 0, 0}, {0, 1, 0}, { 0, 0, 1 } \
  }
#define DETM4X4                                                     \
  {                                                                 \
    {2, 2, 3, 4}, {5, 7, 7, 8}, {9, 10, 12, 12}, { 13, 14, 15, 17 } \
  }
#define M1X1 \
  {          \
    { 1 }    \
  }
#define M2X3               \
  {                        \
    {1, 2, 3}, { 4, 5, 6 } \
  }
#define M2X3t                \
  {                          \
    {1, 4}, {2, 5}, { 3, 6 } \
  }
#define M2X2mr           \
  {                      \
    {14, 32}, { 32, 77 } \
  }

#define M3X3tm                        \
  {                                   \
    {1, 2, 3}, {0, 4, 2}, { 5, 2, 1 } \
  }

#define M3X3tmr                              \
  {                                          \
    {0, 10, -20}, {4, -14, 8}, { -8, -2, 4 } \
  }

/*
Magic code, don't touch*/
#define MATRIX(ROWS, COLUMNS, BLANK, MINT, INDEX) \
  s21_create_matrix(ROWS, COLUMNS, &BLANK);       \
  double BLANK##INDEX[ROWS][COLUMNS] = MINT;      \
  for (int i = 0; i < ROWS; i++) {                \
    for (int j = 0; j < COLUMNS; j++) {           \
      BLANK.matrix[i][j] = BLANK##INDEX[i][j];    \
    }                                             \
  }

START_TEST(i_exist) { ck_assert(1); }
END_TEST

START_TEST(test_create_matrix) {
  matrix_t normal, nonsym, one, zero, too_big;
  ck_assert_int_eq(s21_create_matrix(5, 5, &normal), 0);
  s21_remove_matrix(&normal);
  ck_assert_int_eq(s21_create_matrix(2, 3, &nonsym), 0);
  s21_remove_matrix(&nonsym);
  ck_assert_int_eq(s21_create_matrix(1, 1, &one), 0);
  s21_remove_matrix(&one);
  ck_assert_int_eq(s21_create_matrix(0, 0, &zero), 1);
  ck_assert_int_eq(s21_create_matrix(2147483647, 2147483647, &too_big), 2);
}
END_TEST

START_TEST(test_remove_matrix) {
  matrix_t normal, nonsym, one, null;
  s21_create_matrix(5, 5, &normal);
  s21_remove_matrix(&normal);
  ck_assert_ptr_null(normal.matrix);

  s21_create_matrix(2, 3, &nonsym);
  s21_remove_matrix(&nonsym);
  ck_assert_ptr_null(nonsym.matrix);

  s21_create_matrix(1, 1, &one);
  s21_remove_matrix(&one);
  ck_assert_ptr_null(one.matrix);

  s21_create_matrix(1, 1, &null);
  s21_remove_matrix(&null);
  ck_assert_ptr_null(null.matrix);
  s21_remove_matrix(&null);
  ck_assert_ptr_null(null.matrix);
}
END_TEST

START_TEST(test_eq_matrix) {
  matrix_t A, B;

  MATRIX(4, 4, A, M4X4, 1)
  B = A;
  ck_assert(s21_eq_matrix(&A, &B));
  s21_remove_matrix(&A);

  MATRIX(4, 4, A, M4X4, 2);
  MATRIX(4, 4, B, M4X4, 2);
  ck_assert(s21_eq_matrix(&A, &B));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);

  MATRIX(4, 4, A, M4X4, 3);
  MATRIX(2, 3, B, M2X3, 3);
  ck_assert(!s21_eq_matrix(&A, &B));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);

  MATRIX(4, 4, A, M4X4, 4);
  MATRIX(4, 4, B, DETM4X4, 4);
  ck_assert(!s21_eq_matrix(&A, &B));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
}
END_TEST

START_TEST(test_check_matrix) {
  matrix_t A;

  MATRIX(4, 4, A, M4X4, 1)
  ck_assert_int_eq(s21_check_matrix(&A), OK);
  s21_remove_matrix(&A);

  MATRIX(1, 1, A, M1X1, 2)
  ck_assert_int_eq(s21_check_matrix(&A), OK);
  s21_remove_matrix(&A);

  MATRIX(2, 3, A, M2X3, 3)
  ck_assert_int_eq(s21_check_matrix(&A), OK);
  s21_remove_matrix(&A);

  MATRIX(4, 4, A, M4X4, 4)
  s21_remove_matrix(&A);
  ck_assert_int_eq(s21_check_matrix(&A), INCORRECT_MATRIX);

  MATRIX(4, 4, A, M4X4, 5)
  free(A.matrix[0]);
  A.matrix[0] = NULL;
  ck_assert_int_eq(s21_check_matrix(&A), INCORRECT_MATRIX);
  s21_remove_matrix(&A);

  MATRIX(4, 4, A, M4X4, 6)
  A.rows = 0;
  A.columns = 0;
  ck_assert_int_eq(s21_check_matrix(&A), INCORRECT_MATRIX);
  A.rows = 4;
  A.columns = 4;
  s21_remove_matrix(&A);
}
END_TEST

START_TEST(test_sum_matrix) {
  matrix_t A, B, result, correct;

  MATRIX(4, 4, A, M4X4, 1)
  B = A;
  ck_assert_int_eq(s21_sum_matrix(&A, &B, &result), OK);
  MATRIX(4, 4, correct, M4X4m2, 1)
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, M4X4, 2)
  MATRIX(4, 4, B, M4X4, 2)
  MATRIX(4, 4, correct, M4X4m2, 2)
  ck_assert_int_eq(s21_sum_matrix(&A, &B, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, M4X4, 3)
  MATRIX(4, 4, B, M4X4n, 3)
  MATRIX(4, 4, correct, M4X4z, 3)
  ck_assert_int_eq(s21_sum_matrix(&A, &B, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, M4X4, 4)
  MATRIX(2, 3, B, M2X3, 4)
  ck_assert_int_eq(s21_sum_matrix(&A, &B, &result), CALCULATION_ERROR);
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);

  MATRIX(4, 4, A, M4X4, 5)
  ck_assert_int_eq(s21_sum_matrix(&A, &B, &result), INCORRECT_MATRIX);
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);

  MATRIX(1, 1, A, M1X1, 6)
  MATRIX(1, 1, B, M1X1, 6)
  MATRIX(1, 1, correct, {{2}}, 6)
  ck_assert_int_eq(s21_sum_matrix(&A, &B, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);
}
END_TEST

START_TEST(test_sub_matrix) {
  matrix_t A, B, result, correct;

  MATRIX(4, 4, A, M4X4, 1)
  B = A;
  ck_assert_int_eq(s21_sub_matrix(&A, &B, &result), OK);
  MATRIX(4, 4, correct, M4X4z, 1)
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, M4X4, 2)
  MATRIX(4, 4, B, M4X4, 2)
  MATRIX(4, 4, correct, M4X4z, 2)
  ck_assert_int_eq(s21_sub_matrix(&A, &B, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, M4X4, 3)
  MATRIX(4, 4, B, M4X4n, 3)
  MATRIX(4, 4, correct, M4X4m2, 3)
  ck_assert_int_eq(s21_sub_matrix(&A, &B, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, M4X4, 4)
  MATRIX(2, 3, B, M2X3, 4)
  ck_assert_int_eq(s21_sub_matrix(&A, &B, &result), CALCULATION_ERROR);
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);

  MATRIX(4, 4, A, M4X4, 5)
  ck_assert_int_eq(s21_sub_matrix(&A, &B, &result), INCORRECT_MATRIX);
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);

  MATRIX(1, 1, A, M1X1, 6)
  MATRIX(1, 1, B, M1X1, 6)
  MATRIX(1, 1, correct, {{0}}, 6)
  ck_assert_int_eq(s21_sub_matrix(&A, &B, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);
}
END_TEST

START_TEST(test_mult_number) {
  matrix_t A, result, correct;

  MATRIX(4, 4, A, M4X4, 1)
  ck_assert_int_eq(s21_mult_number(&A, 2, &result), OK);
  MATRIX(4, 4, correct, M4X4m2, 1)
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, M4X4, 2)
  MATRIX(4, 4, correct, M4X4z, 2)
  ck_assert_int_eq(s21_mult_number(&A, 0, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, M4X4, 3)
  MATRIX(4, 4, correct, M4X4, 3)
  ck_assert_int_eq(s21_mult_number(&A, 1, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  ck_assert_int_eq(s21_mult_number(&A, 1, &result), INCORRECT_MATRIX);
  s21_remove_matrix(&result);

  MATRIX(1, 1, A, M1X1, 4)
  MATRIX(1, 1, correct, {{75}}, 4)
  ck_assert_int_eq(s21_mult_number(&A, 75, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);
}
END_TEST

START_TEST(test_mult_matrix) {
  matrix_t A, B, result, correct;

  MATRIX(4, 4, A, M4X4, 1)
  B = A;
  ck_assert_int_eq(s21_mult_matrix(&A, &B, &result), OK);
  MATRIX(4, 4, correct, M4X4mult, 1)
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, M4X4, 2)
  MATRIX(4, 4, B, M4X4, 2)
  MATRIX(4, 4, correct, M4X4mult, 2)
  ck_assert_int_eq(s21_mult_matrix(&A, &B, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, M4X4, 3)
  MATRIX(4, 4, B, E4X4, 3)
  MATRIX(4, 4, correct, M4X4, 3)
  ck_assert_int_eq(s21_mult_matrix(&A, &B, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, M4X4, 4)
  MATRIX(2, 3, B, M2X3, 4)
  ck_assert_int_eq(s21_mult_matrix(&A, &B, &result), CALCULATION_ERROR);
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);

  MATRIX(4, 4, A, M4X4, 5)
  ck_assert_int_eq(s21_mult_matrix(&A, &B, &result), INCORRECT_MATRIX);
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);

  MATRIX(1, 1, A, M1X1, 6)
  MATRIX(1, 1, B, M1X1, 6)
  MATRIX(1, 1, correct, {{1}}, 6)
  ck_assert_int_eq(s21_mult_matrix(&A, &B, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, E4X4, 7)
  MATRIX(4, 4, B, E4X4, 7)
  MATRIX(4, 4, correct, E4X4, 7)
  ck_assert_int_eq(s21_mult_matrix(&A, &B, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(2, 3, A, M2X3, 8)
  MATRIX(3, 2, B, M2X3t, 8)
  MATRIX(2, 2, correct, M2X2mr, 8)
  ck_assert_int_eq(s21_mult_matrix(&A, &B, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);
}
END_TEST

START_TEST(test_transpose) {
  matrix_t A, result, correct;

  MATRIX(4, 4, A, M4X4, 1)
  ck_assert_int_eq(s21_transpose(&A, &result), OK);
  MATRIX(4, 4, correct, M4X4t, 1)
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, E4X4, 2)
  MATRIX(4, 4, correct, E4X4, 2)
  ck_assert_int_eq(s21_transpose(&A, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(2, 3, A, M2X3, 3)
  MATRIX(3, 2, correct, M2X3t, 3)
  ck_assert_int_eq(s21_transpose(&A, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  ck_assert_int_eq(s21_transpose(&A, &result), INCORRECT_MATRIX);
  s21_remove_matrix(&result);

  MATRIX(1, 1, A, M1X1, 4)
  MATRIX(1, 1, correct, {{1}}, 4)
  ck_assert_int_eq(s21_transpose(&A, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);
}
END_TEST

START_TEST(test_determinant) {
  matrix_t A;
  double result;

  MATRIX(4, 4, A, M4X4, 1)
  ck_assert_int_eq(s21_determinant(&A, &result), OK);
  ck_assert_double_eq(result, 0);
  s21_remove_matrix(&A);

  MATRIX(4, 4, A, DETM4X4, 2)
  ck_assert_int_eq(s21_determinant(&A, &result), OK);
  ck_assert_double_eq(result, -45);
  s21_remove_matrix(&A);

  MATRIX(4, 4, A, E4X4, 3)
  ck_assert_int_eq(s21_determinant(&A, &result), OK);
  ck_assert_double_eq(result, 1);
  s21_remove_matrix(&A);

  MATRIX(2, 3, A, M2X3, 4)
  ck_assert_int_eq(s21_determinant(&A, &result), CALCULATION_ERROR);
  s21_remove_matrix(&A);

  MATRIX(1, 1, A, M1X1, 5)
  ck_assert_int_eq(s21_determinant(&A, &result), OK);
  ck_assert_double_eq(result, 1);
  s21_remove_matrix(&A);

  MATRIX(3, 3, A, M3X3tm, 6)
  ck_assert_int_eq(s21_determinant(&A, &result), OK);
  ck_assert_double_eq(result, -40);
  s21_remove_matrix(&A);
}
END_TEST

START_TEST(test_calc_complements) {
  matrix_t A, result, correct;

  MATRIX(3, 3, A, M3X3tm, 1)
  ck_assert_int_eq(s21_calc_complements(&A, &result), OK);
  MATRIX(3, 3, correct, M3X3tmr, 1)

  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, E4X4, 2)
  MATRIX(4, 4, correct, E4X4, 2)
  ck_assert_int_eq(s21_calc_complements(&A, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(2, 3, A, M2X3, 3)
  MATRIX(3, 2, correct, M2X3t, 3)
  ck_assert_int_eq(s21_calc_complements(&A, &result), CALCULATION_ERROR);
  s21_remove_matrix(&A);
  s21_remove_matrix(&correct);
  s21_remove_matrix(&result);

  ck_assert_int_eq(s21_calc_complements(&A, &result), INCORRECT_MATRIX);
  s21_remove_matrix(&result);

  MATRIX(1, 1, A, M1X1, 4)
  MATRIX(1, 1, correct, {{1}}, 4)
  ck_assert_int_eq(s21_calc_complements(&A, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);
}
END_TEST

START_TEST(test_inverse_matrix) {
  matrix_t A, B, result, correct;

  MATRIX(3, 3, A, M3X3tm, 1);
  ck_assert_int_eq(s21_inverse_matrix(&A, &B), OK);
  ck_assert_int_eq(s21_mult_matrix(&A, &B, &result), OK);
  MATRIX(3, 3, correct, E3X3, 1);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, DETM4X4, 2);
  ck_assert_int_eq(s21_inverse_matrix(&A, &B), OK);
  ck_assert_int_eq(s21_mult_matrix(&A, &B, &result), OK);
  MATRIX(4, 4, correct, E4X4, 2);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, E4X4, 3);
  ck_assert_int_eq(s21_inverse_matrix(&A, &B), OK);
  ck_assert_int_eq(s21_mult_matrix(&A, &B, &result), OK);
  MATRIX(4, 4, correct, E4X4, 3);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&B);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(2, 3, A, M2X3, 4);
  ck_assert_int_eq(s21_inverse_matrix(&A, &B), CALCULATION_ERROR);
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  ck_assert_int_eq(s21_inverse_matrix(&A, &result), INCORRECT_MATRIX);
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);

  MATRIX(1, 1, A, {{1}}, 5);
  ck_assert_int_eq(s21_inverse_matrix(&A, &result), OK);
  MATRIX(1, 1, correct, {{1}}, 5);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);

  MATRIX(4, 4, A, E4X4, 6)
  MATRIX(4, 4, correct, E4X4, 6)
  ck_assert_int_eq(s21_inverse_matrix(&A, &result), OK);
  ck_assert(s21_eq_matrix(&result, &correct));
  s21_remove_matrix(&A);
  s21_remove_matrix(&result);
  s21_remove_matrix(&correct);
}
END_TEST

int main() {
  Suite *s;
  SRunner *sr;

  s = suite_create("main");
  TCase *hello_case = tcase_create("core");

  suite_add_tcase(s, hello_case);
  tcase_add_test(hello_case, i_exist);
  tcase_add_test(hello_case, test_create_matrix);
  tcase_add_test(hello_case, test_remove_matrix);
  tcase_add_test(hello_case, test_eq_matrix);
  tcase_add_test(hello_case, test_check_matrix);
  tcase_add_test(hello_case, test_sum_matrix);
  tcase_add_test(hello_case, test_sub_matrix);
  tcase_add_test(hello_case, test_mult_number);
  tcase_add_test(hello_case, test_mult_matrix);
  tcase_add_test(hello_case, test_transpose);
  tcase_add_test(hello_case, test_determinant);
  tcase_add_test(hello_case, test_calc_complements);
  tcase_add_test(hello_case, test_inverse_matrix);

  sr = srunner_create(s);
  srunner_run_all(sr, CK_NORMAL);
  int number_failed = srunner_ntests_failed(sr);
  srunner_free(sr);

  return (number_failed) ? 1 : 0;
}